package GUI;

import ModelLayer.*;
import CtrlLayer.*;

import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class ProductsGUI extends JFrame implements ActionListener{
    private Container container;
    private JPanel panelProducts;
    private JPanel panelCreateProduct;
    private JPanel panelFindProduct;
    private JPanel panelFindProduct2;
    private JPanel panelUpdateProduct;
    private JPanel panelUpdateProduct2;
    private JPanel panelDeleteProduct;
    private JPanel panelDeleteProduct2;
    private ProductController productController;
    private int sessionId;

    public ProductsGUI(int sessionId){
        panelProducts = new JPanel(new GridBagLayout());
        panelCreateProduct = new JPanel(new GridBagLayout());
        panelFindProduct = new JPanel(new GridBagLayout());
        panelFindProduct2 = new JPanel(new GridBagLayout());
        panelUpdateProduct = new JPanel(new GridBagLayout());
        panelUpdateProduct2 = new JPanel(new GridBagLayout());
        panelDeleteProduct = new JPanel(new GridBagLayout());
        panelDeleteProduct2 = new JPanel(new GridBagLayout());
        productController = new ProductController();

        this.sessionId = sessionId;

        this.setTitle("Vestbjerg company system");
        this.setLocation(300,50);
        this.setVisible(true);
        this.setSize(400, 490);
        this.setResizable(false);
        productsMainMenu();
    }

    public void actionPerformed(ActionEvent e){

    }

    public void makeProductsMenu(){
        GridBagConstraints gbc = new GridBagConstraints();

        JButton addProduct = new JButton("Add Product");
        addProduct.setPreferredSize(new Dimension(130, 25));
        addProduct.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    container = getContentPane();
                    container.removeAll();
                    createProduct();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        panelProducts.add(addProduct, gbc);

        JButton showProducts = new JButton("Show Product");
        showProducts.setPreferredSize(new Dimension(130, 25));
        showProducts.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    container = getContentPane();
                    container.removeAll();
                    findProduct();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        panelProducts.add(showProducts, gbc);
        if(SessionContainer.getInstance().findSessionById(sessionId).getAccessLevel() == 2){
            JButton updateProduct = new JButton("Update Product");
            updateProduct.setPreferredSize(new Dimension(130, 25));
            updateProduct.addActionListener(new ActionListener()
                {
                    public void actionPerformed(ActionEvent e){
                        container = getContentPane();
                        container.removeAll();
                        updateProductFirstWindow();
                        container.invalidate();
                        container.revalidate();
                        container.repaint();
                        container.setVisible(true);
                    }
                }
            );
            gbc.gridx = 0;
            gbc.gridy = 3;
            gbc.insets = new Insets(5,5,5,5);
            panelProducts.add(updateProduct, gbc);

            JButton deleteProduct = new JButton("Delete Product");
            deleteProduct.setPreferredSize(new Dimension(130, 25));
            deleteProduct.addActionListener(new ActionListener()
                {
                    public void actionPerformed(ActionEvent e){
                        container = getContentPane();
                        container.removeAll();
                        deleteProductFirstWindow();
                        container.invalidate();
                        container.revalidate();
                        container.repaint();
                        container.setVisible(true);
                    }
                }
            );
            gbc.gridx = 0;
            gbc.gridy = 4;
            gbc.insets = new Insets(5,5,5,5);
            panelProducts.add(deleteProduct, gbc);
        }

        JButton back = new JButton("Close");
        back.setPreferredSize(new Dimension(130, 25));
        back.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    dispose();
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 5;
        gbc.insets = new Insets(5,5,5,5);
        panelProducts.add(back, gbc);
    }

    public void productsMainMenu(){
        makeProductsMenu();
        this.getContentPane().add(panelProducts, BorderLayout.NORTH);
    }

    private void create(){
        JTextField textBarcode = new JTextField();
        JTextField textName = new JTextField();
        JTextField textSellingPrice = new JTextField();
        JTextField textLeasingPrice = new JTextField();
        JTextField textPriceForDiscount = new JTextField();
        JTextField textAmountForDiscount = new JTextField();
        JTextField textMinimumAmount = new JTextField();
        JTextField textMaximumAmount = new JTextField();
        JTextField textAmount = new JTextField();
        JTextField textContractorId = new JTextField();
        JTextField textLocationCode = new JTextField();
        JLabel labelBarcode;
        JLabel labelName;
        JLabel labelSellingPrice;
        JLabel labelLeasingPrice;
        JLabel labelPriceForDiscount;
        JLabel labelAmountForDiscount;
        JLabel labelMinimumAmount;
        JLabel labelMaximumAmount;
        JLabel labelAmount;
        JLabel labelContractorId;
        JLabel labelLocationCode;
        JLabel errorMessage;
        JButton create;
        JButton clear;
        JButton back;
        GridBagConstraints gbc = new GridBagConstraints();

        textBarcode.setText(""); 
        textName.setText("");
        textSellingPrice.setText("");
        textLeasingPrice.setText("");
        textPriceForDiscount.setText("");
        textAmountForDiscount.setText("");
        textMinimumAmount.setText("");
        textMaximumAmount.setText("");
        textAmount.setText("");
        textContractorId.setText("");
        textLocationCode.setText("");

        if(SessionContainer.getInstance().findSessionById(sessionId).getAccessLevel() == 1){
            textSellingPrice.setEditable(false);
            textSellingPrice.setText("0");
            textLeasingPrice.setEditable(false);
            textLeasingPrice.setText("0");
            textPriceForDiscount.setEditable(false);
            textPriceForDiscount.setText("0");
            textAmountForDiscount.setEditable(false);
            textAmountForDiscount.setText("0");
            textMinimumAmount.setEditable(false);
            textMinimumAmount.setText("0");
            textMaximumAmount.setEditable(false);
            textMaximumAmount.setText("0");
        }

        labelBarcode = new JLabel("Barcode:", JLabel.RIGHT);
        labelBarcode.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        panelCreateProduct.add(labelBarcode, gbc);

        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        textBarcode.setPreferredSize(new Dimension(100,25));
        panelCreateProduct.add(textBarcode,gbc);

        labelName = new JLabel("Name:", JLabel.RIGHT);
        labelName.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        panelCreateProduct.add(labelName, gbc);

        gbc.gridx = 1;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        textName.setPreferredSize(new Dimension(100,25));
        panelCreateProduct.add(textName,gbc);

        labelSellingPrice = new JLabel("Selling Price:", JLabel.RIGHT);
        labelSellingPrice.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        panelCreateProduct.add(labelSellingPrice, gbc);

        gbc.gridx = 1;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        textSellingPrice.setPreferredSize(new Dimension(100,25));
        panelCreateProduct.add(textSellingPrice,gbc);

        labelLeasingPrice = new JLabel("Leasing Price:", JLabel.RIGHT);
        labelLeasingPrice.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 3;
        gbc.insets = new Insets(5,5,5,5);
        panelCreateProduct.add(labelLeasingPrice, gbc);

        gbc.gridx = 1;
        gbc.gridy = 3;
        gbc.insets = new Insets(5,5,5,5);
        textLeasingPrice.setPreferredSize(new Dimension(100,25));
        panelCreateProduct.add(textLeasingPrice,gbc);

        labelPriceForDiscount = new JLabel("Price For Discount:", JLabel.RIGHT);
        labelPriceForDiscount.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 4;
        gbc.insets = new Insets(5,5,5,5);
        panelCreateProduct.add(labelPriceForDiscount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 4;
        gbc.insets = new Insets(5,5,5,5);
        textPriceForDiscount.setPreferredSize(new Dimension(100,25));
        panelCreateProduct.add(textPriceForDiscount,gbc);

        labelAmountForDiscount = new JLabel("Amount For Discount:", JLabel.RIGHT);
        labelAmountForDiscount.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 5;
        gbc.insets = new Insets(5,5,5,5);
        panelCreateProduct.add(labelAmountForDiscount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 5;
        gbc.insets = new Insets(5,5,5,5);
        textAmountForDiscount.setPreferredSize(new Dimension(100,25));
        panelCreateProduct.add(textAmountForDiscount,gbc);

        labelMinimumAmount = new JLabel("Minimum Amount:", JLabel.RIGHT);
        labelMinimumAmount.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 6;
        gbc.insets = new Insets(5,5,5,5);
        panelCreateProduct.add(labelMinimumAmount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 6;
        gbc.insets = new Insets(5,5,5,5);
        textMinimumAmount.setPreferredSize(new Dimension(100,25));
        panelCreateProduct.add(textMinimumAmount,gbc);

        labelMaximumAmount = new JLabel("Maximum Amount:", JLabel.RIGHT);
        labelMaximumAmount.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 7;
        gbc.insets = new Insets(5,5,5,5);
        panelCreateProduct.add(labelMaximumAmount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 7;
        gbc.insets = new Insets(5,5,5,5);
        textMaximumAmount.setPreferredSize(new Dimension(100,25));
        panelCreateProduct.add(textMaximumAmount,gbc);

        labelAmount = new JLabel("Amount:", JLabel.RIGHT);
        labelAmount.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 8;
        gbc.insets = new Insets(5,5,5,5);
        panelCreateProduct.add(labelAmount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 8;
        gbc.insets = new Insets(5,5,5,5);
        textAmount.setPreferredSize(new Dimension(100,25));
        panelCreateProduct.add(textAmount,gbc);

        labelContractorId = new JLabel("Contractor ID:", JLabel.RIGHT);
        labelContractorId.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 9;
        gbc.insets = new Insets(5,5,5,5);
        panelCreateProduct.add(labelContractorId, gbc);

        gbc.gridx = 1;
        gbc.gridy = 9;
        gbc.insets = new Insets(5,5,5,5);
        textContractorId.setPreferredSize(new Dimension(100,25));
        panelCreateProduct.add(textContractorId,gbc);

        labelLocationCode = new JLabel("Location code:", JLabel.RIGHT);
        labelLocationCode.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 10;
        gbc.insets = new Insets(5,5,5,5);
        panelCreateProduct.add(labelLocationCode, gbc);

        gbc.gridx = 1;
        gbc.gridy = 10;
        gbc.insets = new Insets(5,5,5,5);
        textLocationCode.setPreferredSize(new Dimension(100,25));
        panelCreateProduct.add(textLocationCode,gbc);

        errorMessage = new JLabel("", JLabel.RIGHT);
        errorMessage.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 11;
        gbc.insets = new Insets(5,5,5,5);
        panelCreateProduct.add(errorMessage, gbc);

        create = new JButton("Create");
        create.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    try{
                        productController.createProduct(Integer.parseInt(textBarcode.getText()), 
                            textName.getText(), 
                            Double.parseDouble(textSellingPrice.getText()), 
                            Double.parseDouble(textLeasingPrice.getText()), 
                            Double.parseDouble(textPriceForDiscount.getText()), 
                            Integer.parseInt(textAmountForDiscount.getText()),
                            Integer.parseInt(textAmount.getText()),
                            Integer.parseInt(textMinimumAmount.getText()),
                            Integer.parseInt(textMaximumAmount.getText()), 
                            Integer.parseInt(textContractorId.getText()),
                            Integer.parseInt(textLocationCode.getText()));

                        container = getContentPane();
                        panelCreateProduct.removeAll();
                        container.removeAll();
                        createProduct();
                        container.invalidate();
                        container.revalidate();
                        container.repaint();
                        container.setVisible(true);

                        textBarcode.setText(""); 
                        textName.setText("");
                        textSellingPrice.setText("");
                        textLeasingPrice.setText("");
                        textPriceForDiscount.setText("");
                        textAmountForDiscount.setText("");
                        textMinimumAmount.setText("");
                        textMaximumAmount.setText("");
                        textAmount.setText("");
                        textContractorId.setText("");
                        textLocationCode.setText("");
                        errorMessage.setText("");
                    }catch(Exception ex){
                        errorMessage.setText("Not possible!");
                        create.setEnabled(false);
                    }
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 12;
        gbc.insets = new Insets(5,5,5,5);
        create.setPreferredSize(new Dimension(130,25));
        panelCreateProduct.add(create,gbc);

        clear = new JButton("Clear");
        clear.addActionListener(new 

            ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    textBarcode.setText(""); 
                    textName.setText("");
                    textSellingPrice.setText("");
                    textLeasingPrice.setText("");
                    textPriceForDiscount.setText("");
                    textAmountForDiscount.setText("");
                    textMinimumAmount.setText("");
                    textMaximumAmount.setText("");
                    textAmount.setText("");
                    textContractorId.setText("");
                    textLocationCode.setText("");
                    errorMessage.setText("");
                    create.setEnabled(true);
                }
            }
        );
        gbc.gridx = 1;
        gbc.gridy = 12;
        gbc.insets = new Insets(5,5,5,5);
        clear.setPreferredSize(new Dimension(100,25));
        panelCreateProduct.add(clear,gbc);

        back = new JButton("Back");
        back.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    textBarcode.setText(""); 
                    textName.setText("");
                    textSellingPrice.setText("");
                    textLeasingPrice.setText("");
                    textPriceForDiscount.setText("");
                    textAmountForDiscount.setText("");
                    textMinimumAmount.setText("");
                    textMaximumAmount.setText("");
                    textAmount.setText("");
                    textContractorId.setText("");
                    textLocationCode.setText("");
                    errorMessage.setText("");
                    container = getContentPane();
                    panelCreateProduct.removeAll();
                    container.removeAll();
                    productsMainMenu();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                }
            }
        );
        gbc.gridx = 2;
        gbc.gridy = 12;
        gbc.insets = new Insets(5,5,5,5);
        back.setPreferredSize(new Dimension(100,25));
        panelCreateProduct.add(back,gbc);
    }

    public void createProduct(){
        create();
        this.getContentPane().add(panelCreateProduct, BorderLayout.NORTH);
    }

    private void find(){
        JTextField textBarcode = new JTextField();
        JLabel labelBarcode;
        JLabel errorMessage;
        JButton find;
        JButton back;
        GridBagConstraints gbc = new GridBagConstraints();

        textBarcode.setText("");

        labelBarcode = new JLabel("Barcode:", JLabel.RIGHT);
        labelBarcode.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        panelFindProduct.add(labelBarcode, gbc);

        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        textBarcode.setPreferredSize(new Dimension(100,25));
        panelFindProduct.add(textBarcode,gbc);

        errorMessage = new JLabel("", JLabel.RIGHT);
        errorMessage.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        panelFindProduct.add(errorMessage, gbc);

        find = new JButton("Search");
        find.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    try{
                        container = getContentPane();
                        container.removeAll();
                        findProductSecondWindow(Integer.parseInt(textBarcode.getText()));
                        container.invalidate();
                        container.revalidate();
                        container.repaint();
                        container.setVisible(true);
                        textBarcode.setText("");
                        errorMessage.setText("");
                    }catch(Exception ex){
                        container = getContentPane();
                        container.removeAll();
                        findProduct();
                        container.invalidate();
                        container.revalidate();
                        container.repaint();
                        container.setVisible(true);
                        textBarcode.setText("");
                        errorMessage.setText("No product!");
                    }
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        find.setPreferredSize(new Dimension(100,25));
        panelFindProduct.add(find,gbc);

        back = new JButton("Back");
        back.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    container = getContentPane();
                    container.removeAll();
                    productsMainMenu();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                    textBarcode.setText("");
                    errorMessage.setText("");
                }
            }
        );
        gbc.gridx = 1;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        back.setPreferredSize(new Dimension(100,25));
        panelFindProduct.add(back,gbc);
    }

    public void findProduct()
    {
        find();
        this.getContentPane().add(panelFindProduct, BorderLayout.NORTH);
    }

    public void findSecondWindow(int barcode){
        JTextField textBarcode = new JTextField();
        JTextField textName = new JTextField();
        JTextField textSellingPrice = new JTextField();
        JTextField textLeasingPrice = new JTextField();
        JTextField textPriceForDiscount = new JTextField();
        JTextField textAmountForDiscount = new JTextField();
        JTextField textMinimumAmount = new JTextField();
        JTextField textMaximumAmount = new JTextField();
        JTextField textAmount = new JTextField();
        JTextField textContractorId = new JTextField();
        JTextField textLocationCode = new JTextField();
        JLabel labelBarcode;
        JLabel labelName;
        JLabel labelSellingPrice;
        JLabel labelLeasingPrice;
        JLabel labelPriceForDiscount;
        JLabel labelAmountForDiscount;
        JLabel labelMinimumAmount;
        JLabel labelMaximumAmount;
        JLabel labelAmount;
        JLabel labelContractorId;
        JLabel labelLocationCode;
        JButton ok;
        GridBagConstraints gbc = new GridBagConstraints();

        textBarcode.setEditable(false); 
        textName.setEditable(false);
        textSellingPrice.setEditable(false);
        textLeasingPrice.setEditable(false);
        textPriceForDiscount.setEditable(false);
        textAmountForDiscount.setEditable(false);
        textMinimumAmount.setEditable(false);
        textMaximumAmount.setEditable(false);
        textAmount.setEditable(false);
        textContractorId.setEditable(false);
        textLocationCode.setEditable(false);

        textBarcode.setText(Integer.toString(productController.findProduct(barcode).getBarcode()));
        textName.setText(productController.findProduct(barcode).getName());
        textSellingPrice.setText(Double.toString(productController.findProduct(barcode).getSellingPrice()));
        textLeasingPrice.setText(Double.toString(productController.findProduct(barcode).getLeasingPrice()));
        textPriceForDiscount.setText(Double.toString(productController.findProduct(barcode).getPriceForDiscount()));
        textAmountForDiscount.setText(Integer.toString(productController.findProduct(barcode).getAmountForDiscount()));
        textMinimumAmount.setText(Integer.toString(productController.findProduct(barcode).getMinAmount()));
        textMaximumAmount.setText(Integer.toString(productController.findProduct(barcode).getMaxAmount()));
        textAmount.setText(Integer.toString(productController.findProduct(barcode).getAmount()));
        textContractorId.setText(Integer.toString(productController.findProduct(barcode).getContractorId()));
        textLocationCode.setText(Integer.toString(productController.findProduct(barcode).getLocationCode()));

        labelBarcode = new JLabel("Barcode:", JLabel.RIGHT);
        labelBarcode.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        panelFindProduct2.add(labelBarcode, gbc);

        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        textBarcode.setPreferredSize(new Dimension(100,25));
        panelFindProduct2.add(textBarcode,gbc);

        labelName = new JLabel("Name:", JLabel.RIGHT);
        labelName.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        panelFindProduct2.add(labelName, gbc);

        gbc.gridx = 1;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        textName.setPreferredSize(new Dimension(100,25));
        panelFindProduct2.add(textName,gbc);

        labelSellingPrice = new JLabel("Selling Price:", JLabel.RIGHT);
        labelSellingPrice.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        panelFindProduct2.add(labelSellingPrice, gbc);

        gbc.gridx = 1;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        textSellingPrice.setPreferredSize(new Dimension(100,25));
        panelFindProduct2.add(textSellingPrice,gbc);

        labelLeasingPrice = new JLabel("Leasing Price:", JLabel.RIGHT);
        labelLeasingPrice.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 3;
        gbc.insets = new Insets(5,5,5,5);
        panelFindProduct2.add(labelLeasingPrice, gbc);

        gbc.gridx = 1;
        gbc.gridy = 3;
        gbc.insets = new Insets(5,5,5,5);
        textLeasingPrice.setPreferredSize(new Dimension(100,25));
        panelFindProduct2.add(textLeasingPrice,gbc);

        labelPriceForDiscount = new JLabel("Price For Discount:", JLabel.RIGHT);
        labelPriceForDiscount.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 4;
        gbc.insets = new Insets(5,5,5,5);
        panelFindProduct2.add(labelPriceForDiscount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 4;
        gbc.insets = new Insets(5,5,5,5);
        textPriceForDiscount.setPreferredSize(new Dimension(100,25));
        panelFindProduct2.add(textPriceForDiscount,gbc);

        labelAmountForDiscount = new JLabel("Amount For Discount:", JLabel.RIGHT);
        labelAmountForDiscount.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 5;
        gbc.insets = new Insets(5,5,5,5);
        panelFindProduct2.add(labelAmountForDiscount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 5;
        gbc.insets = new Insets(5,5,5,5);
        textAmountForDiscount.setPreferredSize(new Dimension(100,25));
        panelFindProduct2.add(textAmountForDiscount,gbc);

        labelMinimumAmount = new JLabel("Minimum Amount:", JLabel.RIGHT);
        labelMinimumAmount.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 6;
        gbc.insets = new Insets(5,5,5,5);
        panelFindProduct2.add(labelMinimumAmount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 6;
        gbc.insets = new Insets(5,5,5,5);
        textMinimumAmount.setPreferredSize(new Dimension(100,25));
        panelFindProduct2.add(textMinimumAmount,gbc);

        labelMaximumAmount = new JLabel("Maximum Amount:", JLabel.RIGHT);
        labelMaximumAmount.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 7;
        gbc.insets = new Insets(5,5,5,5);
        panelFindProduct2.add(labelMaximumAmount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 7;
        gbc.insets = new Insets(5,5,5,5);
        textMaximumAmount.setPreferredSize(new Dimension(100,25));
        panelFindProduct2.add(textMaximumAmount,gbc);

        labelAmount = new JLabel("Amount:", JLabel.RIGHT);
        labelAmount.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 8;
        gbc.insets = new Insets(5,5,5,5);
        panelFindProduct2.add(labelAmount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 8;
        gbc.insets = new Insets(5,5,5,5);
        textAmount.setPreferredSize(new Dimension(100,25));
        panelFindProduct2.add(textAmount,gbc);

        labelContractorId = new JLabel("Contractor ID:", JLabel.RIGHT);
        labelContractorId.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 9;
        gbc.insets = new Insets(5,5,5,5);
        panelFindProduct2.add(labelContractorId, gbc);

        gbc.gridx = 1;
        gbc.gridy = 9;
        gbc.insets = new Insets(5,5,5,5);
        textContractorId.setPreferredSize(new Dimension(100,25));
        panelFindProduct2.add(textContractorId,gbc);

        labelLocationCode = new JLabel("Location code:", JLabel.RIGHT);
        labelLocationCode.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 10;
        gbc.insets = new Insets(5,5,5,5);
        panelFindProduct2.add(labelLocationCode, gbc);

        gbc.gridx = 1;
        gbc.gridy = 10;
        gbc.insets = new Insets(5,5,5,5);
        textLocationCode.setPreferredSize(new Dimension(100,25));
        panelFindProduct2.add(textLocationCode,gbc);

        ok = new JButton("OK");
        ok.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    container = getContentPane();
                    container.removeAll();
                    findProduct();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 11;
        gbc.insets = new Insets(5,5,5,5);
        ok.setPreferredSize(new Dimension(100,25));
        panelFindProduct2.add(ok,gbc);
    }

    public void findProductSecondWindow(int barcode){
        findSecondWindow(barcode);
        this.getContentPane().add(panelFindProduct2, BorderLayout.NORTH);
    }

    private void updateFirstWindow(){
        JTextField textBarcode = new JTextField();
        JLabel labelBarcode;
        JLabel errorMessage;
        JButton find;
        JButton back;
        GridBagConstraints gbc = new GridBagConstraints();

        textBarcode.setText("");

        labelBarcode = new JLabel("Barcode:", JLabel.RIGHT);
        labelBarcode.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        panelUpdateProduct.add(labelBarcode, gbc);

        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        textBarcode.setPreferredSize(new Dimension(100,25));
        panelUpdateProduct.add(textBarcode,gbc);

        errorMessage = new JLabel("", JLabel.RIGHT);
        errorMessage.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        panelUpdateProduct.add(errorMessage, gbc);

        find = new JButton("Search");
        find.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    try{
                        container = getContentPane();
                        container.removeAll();
                        updateProductSecondWindow(Integer.parseInt(textBarcode.getText()));
                        container.invalidate();
                        container.revalidate();
                        container.repaint();
                        container.setVisible(true);
                        textBarcode.setText("");
                        errorMessage.setText("");
                    }catch(Exception ex){
                        container = getContentPane();
                        container.removeAll();
                        updateProductFirstWindow();
                        container.invalidate();
                        container.revalidate();
                        container.repaint();
                        container.setVisible(true);
                        textBarcode.setText("");
                        errorMessage.setText("No product!");
                    }
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        find.setPreferredSize(new Dimension(100,25));
        panelUpdateProduct.add(find,gbc);

        back = new JButton("Back");
        back.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    container = getContentPane();
                    container.removeAll();
                    productsMainMenu();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                    textBarcode.setText("");
                    errorMessage.setText("");
                }
            }
        );
        gbc.gridx = 1;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        back.setPreferredSize(new Dimension(100,25));
        panelUpdateProduct.add(back,gbc);
    }

    public void updateProductFirstWindow()
    {
        updateFirstWindow();
        this.getContentPane().add(panelUpdateProduct, BorderLayout.NORTH);
    }

    private void updateSecondWindow(int barcode){
        JTextField textBarcode = new JTextField();
        JTextField textName = new JTextField();
        JTextField textSellingPrice = new JTextField();
        JTextField textLeasingPrice = new JTextField();
        JTextField textPriceForDiscount = new JTextField();
        JTextField textAmountForDiscount = new JTextField();
        JTextField textMinimumAmount = new JTextField();
        JTextField textMaximumAmount = new JTextField();
        JTextField textAmount = new JTextField();
        JTextField textContractorId = new JTextField();
        JTextField textLocationCode = new JTextField();
        JLabel labelBarcode;
        JLabel labelName;
        JLabel labelSellingPrice;
        JLabel labelLeasingPrice;
        JLabel labelPriceForDiscount;
        JLabel labelAmountForDiscount;
        JLabel labelMinimumAmount;
        JLabel labelMaximumAmount;
        JLabel labelAmount;
        JLabel labelContractorId;
        JLabel labelLocationCode;
        JButton update;
        JButton cancel;
        GridBagConstraints gbc = new GridBagConstraints();

        textBarcode.setText(Integer.toString(productController.findProduct(barcode).getBarcode()));
        textName.setText(productController.findProduct(barcode).getName());
        textSellingPrice.setText(Double.toString(productController.findProduct(barcode).getSellingPrice()));
        textLeasingPrice.setText(Double.toString(productController.findProduct(barcode).getLeasingPrice()));
        textPriceForDiscount.setText(Double.toString(productController.findProduct(barcode).getPriceForDiscount()));
        textAmountForDiscount.setText(Integer.toString(productController.findProduct(barcode).getAmountForDiscount()));
        textMinimumAmount.setText(Integer.toString(productController.findProduct(barcode).getMinAmount()));
        textMaximumAmount.setText(Integer.toString(productController.findProduct(barcode).getMaxAmount()));
        textAmount.setText(Integer.toString(productController.findProduct(barcode).getAmount()));
        textContractorId.setText(Integer.toString(productController.findProduct(barcode).getContractorId()));
        textLocationCode.setText(Integer.toString(productController.findProduct(barcode).getLocationCode()));

        labelBarcode = new JLabel("Barcode:", JLabel.RIGHT);
        labelBarcode.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        panelUpdateProduct2.add(labelBarcode, gbc);

        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        textBarcode.setPreferredSize(new Dimension(100,25));
        panelUpdateProduct2.add(textBarcode,gbc);

        labelName = new JLabel("Name:", JLabel.RIGHT);
        labelName.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        panelUpdateProduct2.add(labelName, gbc);

        gbc.gridx = 1;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        textName.setPreferredSize(new Dimension(100,25));
        panelUpdateProduct2.add(textName,gbc);

        labelSellingPrice = new JLabel("Selling Price:", JLabel.RIGHT);
        labelSellingPrice.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        panelUpdateProduct2.add(labelSellingPrice, gbc);

        gbc.gridx = 1;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        textSellingPrice.setPreferredSize(new Dimension(100,25));
        panelUpdateProduct2.add(textSellingPrice,gbc);

        labelLeasingPrice = new JLabel("Leasing Price:", JLabel.RIGHT);
        labelLeasingPrice.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 3;
        gbc.insets = new Insets(5,5,5,5);
        panelUpdateProduct2.add(labelLeasingPrice, gbc);

        gbc.gridx = 1;
        gbc.gridy = 3;
        gbc.insets = new Insets(5,5,5,5);
        textLeasingPrice.setPreferredSize(new Dimension(100,25));
        panelUpdateProduct2.add(textLeasingPrice,gbc);

        labelPriceForDiscount = new JLabel("Price For Discount:", JLabel.RIGHT);
        labelPriceForDiscount.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 4;
        gbc.insets = new Insets(5,5,5,5);
        panelUpdateProduct2.add(labelPriceForDiscount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 4;
        gbc.insets = new Insets(5,5,5,5);
        textPriceForDiscount.setPreferredSize(new Dimension(100,25));
        panelUpdateProduct2.add(textPriceForDiscount,gbc);

        labelAmountForDiscount = new JLabel("Amount For Discount:", JLabel.RIGHT);
        labelAmountForDiscount.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 5;
        gbc.insets = new Insets(5,5,5,5);
        panelUpdateProduct2.add(labelAmountForDiscount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 5;
        gbc.insets = new Insets(5,5,5,5);
        textAmountForDiscount.setPreferredSize(new Dimension(100,25));
        panelUpdateProduct2.add(textAmountForDiscount,gbc);

        labelMinimumAmount = new JLabel("Minimum Amount:", JLabel.RIGHT);
        labelMinimumAmount.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 6;
        gbc.insets = new Insets(5,5,5,5);
        panelUpdateProduct2.add(labelMinimumAmount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 6;
        gbc.insets = new Insets(5,5,5,5);
        textMinimumAmount.setPreferredSize(new Dimension(100,25));
        panelUpdateProduct2.add(textMinimumAmount,gbc);

        labelMaximumAmount = new JLabel("Maximum Amount:", JLabel.RIGHT);
        labelMaximumAmount.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 7;
        gbc.insets = new Insets(5,5,5,5);
        panelUpdateProduct2.add(labelMaximumAmount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 7;
        gbc.insets = new Insets(5,5,5,5);
        textMaximumAmount.setPreferredSize(new Dimension(100,25));
        panelUpdateProduct2.add(textMaximumAmount,gbc);

        labelAmount = new JLabel("Amount:", JLabel.RIGHT);
        labelAmount.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 8;
        gbc.insets = new Insets(5,5,5,5);
        panelUpdateProduct2.add(labelAmount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 8;
        gbc.insets = new Insets(5,5,5,5);
        textAmount.setPreferredSize(new Dimension(100,25));
        panelUpdateProduct2.add(textAmount,gbc);

        labelContractorId = new JLabel("Contractor ID:", JLabel.RIGHT);
        labelContractorId.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 9;
        gbc.insets = new Insets(5,5,5,5);
        panelUpdateProduct2.add(labelContractorId, gbc);

        gbc.gridx = 1;
        gbc.gridy = 9;
        gbc.insets = new Insets(5,5,5,5);
        textContractorId.setPreferredSize(new Dimension(100,25));
        panelUpdateProduct2.add(textContractorId,gbc);

        labelLocationCode = new JLabel("Location code:", JLabel.RIGHT);
        labelLocationCode.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 10;
        gbc.insets = new Insets(5,5,5,5);
        panelUpdateProduct2.add(labelLocationCode, gbc);

        gbc.gridx = 1;
        gbc.gridy = 10;
        gbc.insets = new Insets(5,5,5,5);
        textLocationCode.setPreferredSize(new Dimension(100,25));
        panelUpdateProduct2.add(textLocationCode,gbc);

        update = new JButton("Update");
        update.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    productController.updateProduct(Integer.parseInt(textBarcode.getText()),
                        textName.getText(), 
                        Double.parseDouble(textSellingPrice.getText()), 
                        Double.parseDouble(textLeasingPrice.getText()), 
                        Double.parseDouble(textPriceForDiscount.getText()), 
                        Integer.parseInt(textAmountForDiscount.getText()),
                        Integer.parseInt(textAmount.getText()),
                        Integer.parseInt(textMinimumAmount.getText()),
                        Integer.parseInt(textMaximumAmount.getText()),
                        Integer.parseInt(textContractorId.getText()),
                        Integer.parseInt(textLocationCode.getText()));
                    container.removeAll();
                    updateProductFirstWindow();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 11;
        gbc.insets = new Insets(5,5,5,5);
        update.setPreferredSize(new Dimension(100,25));
        panelUpdateProduct2.add(update,gbc);

        cancel = new JButton("Cancel");
        cancel.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    container = getContentPane();
                    container.removeAll();
                    updateProductFirstWindow();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                }
            }
        );
        gbc.gridx = 1;
        gbc.gridy = 11;
        gbc.insets = new Insets(5,5,5,5);
        cancel.setPreferredSize(new Dimension(100,25));
        panelUpdateProduct2.add(cancel,gbc);
    }

    public void updateProductSecondWindow(int barcode)
    {
        updateSecondWindow(barcode);
        this.getContentPane().add(panelUpdateProduct2, BorderLayout.NORTH);
    }

    private void deleteFirstWindow()
    {
        JTextField textBarcode = new JTextField();
        JLabel labelBarcode;
        JLabel errorMessage;
        JButton find;
        JButton back;
        GridBagConstraints gbc = new GridBagConstraints();

        textBarcode.setText("");

        labelBarcode = new JLabel("Barcode:", JLabel.RIGHT);
        labelBarcode.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        panelDeleteProduct.add(labelBarcode, gbc);

        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        textBarcode.setPreferredSize(new Dimension(100,25));
        panelDeleteProduct.add(textBarcode,gbc);

        errorMessage = new JLabel("", JLabel.RIGHT);
        errorMessage.setPreferredSize(new Dimension(100, 25));
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        panelDeleteProduct.add(errorMessage, gbc);

        find = new JButton("Search");
        find.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    try{
                        container = getContentPane();
                        container.removeAll();
                        deleteProductSecondWindow(Integer.parseInt(textBarcode.getText()));
                        container.invalidate();
                        container.revalidate();
                        container.repaint();
                        container.setVisible(true);
                        textBarcode.setText("");
                        errorMessage.setText("");
                    }catch(Exception ex){
                        container = getContentPane();
                        container.removeAll();
                        deleteProductFirstWindow();
                        container.invalidate();
                        container.revalidate();
                        container.repaint();
                        container.setVisible(true);
                        textBarcode.setText("");
                        errorMessage.setText("No product!");
                    }
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        find.setPreferredSize(new Dimension(100,25));
        panelDeleteProduct.add(find,gbc);

        back = new JButton("Back");
        back.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    container = getContentPane();
                    container.removeAll();
                    productsMainMenu();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                    textBarcode.setText("");
                    errorMessage.setText("");
                }
            }
        );
        gbc.gridx = 1;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        back.setPreferredSize(new Dimension(100,25));
        panelDeleteProduct.add(back,gbc);
    }

    private void deleteProductFirstWindow(){
        deleteFirstWindow();
        this.getContentPane().add(panelDeleteProduct, BorderLayout.NORTH);
    }

    private void deleteSecondWindow(int barcode)
    {
        JTextField textBarcode = new JTextField();
        JTextField textName = new JTextField();
        JTextField textSellingPrice = new JTextField();
        JTextField textLeasingPrice = new JTextField();
        JTextField textPriceForDiscount = new JTextField();
        JTextField textAmountForDiscount = new JTextField();
        JTextField textMinimumAmount = new JTextField();
        JTextField textMaximumAmount = new JTextField();
        JTextField textAmount = new JTextField();
        JTextField textContractorId = new JTextField();
        JTextField textLocationCode = new JTextField();
        JLabel labelBarcode;
        JLabel labelName;
        JLabel labelSellingPrice;
        JLabel labelLeasingPrice;
        JLabel labelPriceForDiscount;
        JLabel labelAmountForDiscount;
        JLabel labelMinimumAmount;
        JLabel labelMaximumAmount;
        JLabel labelAmount;
        JLabel labelContractorId;
        JLabel labelLocationCode;
        JButton delete;
        JButton cancel;
        GridBagConstraints gbc = new GridBagConstraints();

        textBarcode.setEditable(false); 
        textName.setEditable(false);
        textSellingPrice.setEditable(false);
        textLeasingPrice.setEditable(false);
        textPriceForDiscount.setEditable(false);
        textAmountForDiscount.setEditable(false);
        textMinimumAmount.setEditable(false);
        textMaximumAmount.setEditable(false);
        textAmount.setEditable(false);
        textContractorId.setEditable(false);
        textLocationCode.setEditable(false);

        textBarcode.setText(Integer.toString(productController.findProduct(barcode).getBarcode()));
        textName.setText(productController.findProduct(barcode).getName());
        textSellingPrice.setText(Double.toString(productController.findProduct(barcode).getSellingPrice()));
        textLeasingPrice.setText(Double.toString(productController.findProduct(barcode).getLeasingPrice()));
        textPriceForDiscount.setText(Double.toString(productController.findProduct(barcode).getPriceForDiscount()));
        textAmountForDiscount.setText(Integer.toString(productController.findProduct(barcode).getAmountForDiscount()));
        textMinimumAmount.setText(Integer.toString(productController.findProduct(barcode).getMinAmount()));
        textMaximumAmount.setText(Integer.toString(productController.findProduct(barcode).getMaxAmount()));
        textAmount.setText(Integer.toString(productController.findProduct(barcode).getAmount()));
        textContractorId.setText(Integer.toString(productController.findProduct(barcode).getContractorId()));
        textLocationCode.setText(Integer.toString(productController.findProduct(barcode).getLocationCode()));

        labelBarcode = new JLabel("Barcode:", JLabel.RIGHT);
        labelBarcode.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        panelDeleteProduct2.add(labelBarcode, gbc);

        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.insets = new Insets(5,5,5,5);
        textBarcode.setPreferredSize(new Dimension(100,25));
        panelDeleteProduct2.add(textBarcode,gbc);

        labelName = new JLabel("Name:", JLabel.RIGHT);
        labelName.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        panelDeleteProduct2.add(labelName, gbc);

        gbc.gridx = 1;
        gbc.gridy = 1;
        gbc.insets = new Insets(5,5,5,5);
        textName.setPreferredSize(new Dimension(100,25));
        panelDeleteProduct2.add(textName,gbc);

        labelSellingPrice = new JLabel("Selling Price:", JLabel.RIGHT);
        labelSellingPrice.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        panelDeleteProduct2.add(labelSellingPrice, gbc);

        gbc.gridx = 1;
        gbc.gridy = 2;
        gbc.insets = new Insets(5,5,5,5);
        textSellingPrice.setPreferredSize(new Dimension(100,25));
        panelDeleteProduct2.add(textSellingPrice,gbc);

        labelLeasingPrice = new JLabel("Leasing Price:", JLabel.RIGHT);
        labelLeasingPrice.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 3;
        gbc.insets = new Insets(5,5,5,5);
        panelDeleteProduct2.add(labelLeasingPrice, gbc);

        gbc.gridx = 1;
        gbc.gridy = 3;
        gbc.insets = new Insets(5,5,5,5);
        textLeasingPrice.setPreferredSize(new Dimension(100,25));
        panelDeleteProduct2.add(textLeasingPrice,gbc);

        labelPriceForDiscount = new JLabel("Price For Discount:", JLabel.RIGHT);
        labelPriceForDiscount.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 4;
        gbc.insets = new Insets(5,5,5,5);
        panelDeleteProduct2.add(labelPriceForDiscount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 4;
        gbc.insets = new Insets(5,5,5,5);
        textPriceForDiscount.setPreferredSize(new Dimension(100,25));
        panelDeleteProduct2.add(textPriceForDiscount,gbc);

        labelAmountForDiscount = new JLabel("Amount For Discount:", JLabel.RIGHT);
        labelAmountForDiscount.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 5;
        gbc.insets = new Insets(5,5,5,5);
        panelDeleteProduct2.add(labelAmountForDiscount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 5;
        gbc.insets = new Insets(5,5,5,5);
        textAmountForDiscount.setPreferredSize(new Dimension(100,25));
        panelDeleteProduct2.add(textAmountForDiscount,gbc);

        labelMinimumAmount = new JLabel("Minimum Amount:", JLabel.RIGHT);
        labelMinimumAmount.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 6;
        gbc.insets = new Insets(5,5,5,5);
        panelDeleteProduct2.add(labelMinimumAmount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 6;
        gbc.insets = new Insets(5,5,5,5);
        textMinimumAmount.setPreferredSize(new Dimension(100,25));
        panelDeleteProduct2.add(textMinimumAmount,gbc);

        labelMaximumAmount = new JLabel("Maximum Amount:", JLabel.RIGHT);
        labelMaximumAmount.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 7;
        gbc.insets = new Insets(5,5,5,5);
        panelDeleteProduct2.add(labelMaximumAmount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 7;
        gbc.insets = new Insets(5,5,5,5);
        textMaximumAmount.setPreferredSize(new Dimension(100,25));
        panelDeleteProduct2.add(textMaximumAmount,gbc);

        labelAmount = new JLabel("Amount:", JLabel.RIGHT);
        labelAmount.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 8;
        gbc.insets = new Insets(5,5,5,5);
        panelDeleteProduct2.add(labelAmount, gbc);

        gbc.gridx = 1;
        gbc.gridy = 8;
        gbc.insets = new Insets(5,5,5,5);
        textAmount.setPreferredSize(new Dimension(100,25));
        panelDeleteProduct2.add(textAmount,gbc);

        labelContractorId = new JLabel("Contractor ID:", JLabel.RIGHT);
        labelContractorId.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 9;
        gbc.insets = new Insets(5,5,5,5);
        panelDeleteProduct2.add(labelContractorId, gbc);

        gbc.gridx = 1;
        gbc.gridy = 9;
        gbc.insets = new Insets(5,5,5,5);
        textContractorId.setPreferredSize(new Dimension(100,25));
        panelDeleteProduct2.add(textContractorId,gbc);

        labelLocationCode = new JLabel("Location code:", JLabel.RIGHT);
        labelLocationCode.setPreferredSize(new Dimension(130, 25));
        gbc.gridx = 0;
        gbc.gridy = 10;
        gbc.insets = new Insets(5,5,5,5);
        panelDeleteProduct2.add(labelLocationCode, gbc);

        gbc.gridx = 1;
        gbc.gridy = 10;
        gbc.insets = new Insets(5,5,5,5);
        textLocationCode.setPreferredSize(new Dimension(100,25));
        panelDeleteProduct2.add(textLocationCode,gbc);

        delete = new JButton("Delete");
        delete.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    productController.deleteProduct(barcode);
                    container = getContentPane();
                    container.removeAll();
                    deleteProductFirstWindow();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                }
            }
        );
        gbc.gridx = 0;
        gbc.gridy = 11;
        gbc.insets = new Insets(5,5,5,5);
        delete.setPreferredSize(new Dimension(100,25));
        panelDeleteProduct2.add(delete,gbc);

        cancel = new JButton("Cancel");
        cancel.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e){
                    container = getContentPane();
                    container.removeAll();
                    deleteProductFirstWindow();
                    container.invalidate();
                    container.revalidate();
                    container.repaint();
                    container.setVisible(true);
                }
            }
        );
        gbc.gridx = 1;
        gbc.gridy = 11;
        gbc.insets = new Insets(5,5,5,5);
        cancel.setPreferredSize(new Dimension(100,25));
        panelDeleteProduct2.add(cancel, gbc);
    }

    private void deleteProductSecondWindow(int barcode){
        deleteSecondWindow(barcode);
        this.getContentPane().add(panelDeleteProduct2, BorderLayout.NORTH);
    }
}
